package com.culture.bootdemo.mq.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;


/**
 * @author: wen
 * @date 2020/9/28
 */
@Configuration
public class RedisMessageListener {

    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
                                                   MessageListenerAdapter listenerAdapter,
                                                   MessageListenerAdapter listenerAdapter2) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(listenerAdapter, new PatternTopic("mytopic"));
        container.addMessageListener(listenerAdapter2, new PatternTopic("mytopic2"));
        return container;
    }


    @Bean
    public MessageListenerAdapter listenerAdapter() {
        return new MessageListenerAdapter(new Receiver(), "receiveMessage");
    }

    @Bean
    public MessageListenerAdapter listenerAdapter2() {
        //第二个参数 对应着类的方法名  反射原理
        return new MessageListenerAdapter(new Receiver2(), "dealData");
    }

}
